<extend name="./public/frame.html"/>
<block name="content">
	<div class="layui-row">
		<div class="layui-col-xs3">
			<div class="layui-btn-group">
				<!--  <button class="layui-btn" data-type="search">搜索</button> -->
				<button class="layui-btn layui-btn-warm" data-url="{:url('region_add')}" onclick="add_t(this,'添加城市')">
					添加城市
				</button>
			</div>
		</div>
	</div>
	<table class="layui-table"
		   lay-data="{width:'auto', height:'auto', url:'{:url('System/region')}', page: true, limit: 10, id:'test'}"
		   lay-filter="test">
		<thead>
		<tr>
			<th lay-data="{checkbox:true, fixed: true}"></th>
			<th lay-data="{field:'zone_id', width:70, fixed: true, sort: true}">ID</th>
			<th lay-data="{field:'zone_name', width:150, fixed: true, sort: true}">城市名称</th>
			<th lay-data="{field:'first_name', width:100, sort: true}">首字母</th>
			<th lay-data="{field:'minute', width:150, sort: true}">分钟价格(元)</th>
			<th lay-data="{field:'start', width:120, sort: true}">起始公里</th>
			<th lay-data="{field:'val_init', width:120, sort: true}">起始价(元)</th>
			<th lay-data="{field:'user_punish', width:150, sort: true}">投诉罚款(元)</th>
			<th lay-data="{field:'order_punish', width:150, sort: true}">司机恶意退单(元)</th>
			<th lay-data="{field:'is_netcar', width:100,templet: '#netcarTpl',align:'center'}">网约车状态</th>
			<th lay-data="{field:'is_taxi', width:100,templet: '#taxiTpl',align:'center'}">出租车状态</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:250, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>
	
	<script type="text/html" id="barDemo">
		{{# if(d.is_use == 1){ }}
		<a class="layui-btn layui-btn-sm">正常</a>
		{{# }else{ }}
		<a class="layui-btn layui-btn-sm" style="width: 50px;height: 15px">未开通</a>
		{{# } }}
		<a class="layui-btn layui-btn-sm" lay-event="look" style="width: 70px">查看价格</a>
		<a class="layui-btn layui-btn-sm" lay-event="edit" style="width: 70px">修改</a>
	 
	</script>
	<!--<script type="text/html" id="interTpl">
		<input type="checkbox" name="is_inter" data-id="{{d.zone_id}}" value="{{d.is_inter}}"
			   lay-skin="switch" lay-text="开启|关闭" lay-filter="is_inter" {{ d.is_inter == 1 ? 'checked' : '' }}>
	</script>-->
	<script type="text/html" id="netcarTpl">
		<input type="checkbox" name="status" data-id="{{d.zone_id}}" value="{{d.is_netcar}}"
			   lay-skin="switch" lay-text="开启|关闭" lay-filter="is_netcar" {{ d.is_netcar == 1 ? 'checked' : '' }}>
	</script>
	<script type="text/html" id="taxiTpl">
		<input type="checkbox" name="status" data-id="{{d.zone_id}}" value="{{d.is_taxi}}"
			   lay-skin="switch" lay-text="开启|关闭" lay-filter="is_taxi" {{ d.is_taxi == 1 ? 'checked' : '' }}>
	</script>

	<script>
		layui.use(['table','form'], function () {
			var table = layui.table;
			var form = layui.form;
			var url = "{:url('is_open')}";
			//监听工具条
			table.on('tool(test)', function (obj) {
				var data = obj.data;
				var zone_id = data.zone_id;
				if (obj.event === 'look') {
					layer.open({
						type: 2,
						title: '收费价格情况',
						shadeClose: true,
						shade: 0.8,
						area: ['480px', '80%'],
						content: '{:url("/admin/system/look","zone_id=")}' + zone_id //iframe的url
					});
				} else if (obj.event === 'edit') {
					var url = "{:url('region_edit','zone_id=')}" + zone_id;
					var index = layui.layer.open({
						title: '编辑城市设置',
						type: 2,
						content: url,
						success: function (layero, index) {
						}
					});
					//改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
					$(window).resize(function () {
						layui.layer.full(index);
					});
					layui.layer.full(index);
				}
			});
			form.on('switch(is_netcar)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
						$.post(url, {'id': id,'value':value,'type':1}, function (data) {
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						}, 'json');
						layer.close(index);
					})
			});
			form.on('switch(is_taxi)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
						$.post(url, {'id': id,'value':value,'type':2}, function (data) {
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						}, 'json');
						layer.close(index);
					})
			});
			form.on('switch(is_inter)', function(obj){
				var ori = obj.elem.checked == true ? false : true;//在没有操作前加载的复选框属性值
				var id = obj.elem.dataset.id;
				var tip = ori == true ? '确定关闭么?' : '确定开启么?';
				var value = ori == true ? 0 : 1;
				layer.confirm(tip, {icon: 3, title: '提示'},	function (index) {
						$.post(url, {'id': id,'value':value,'type':3}, function (data) {
							if(data.status == 1){
								layer.msg(data.msg,{'icon':1});
							}else{
								layer.msg(data.msg,{'icon':2});
							}
						}, 'json');
						layer.close(index);
					})
			});
		});
		layui.use('laydate', function () {
			var laydate = layui.laydate;

			//墨绿主题
			laydate.render({
				elem: '#test6-1' //指定元素
				, type: 'datetime'
				, theme: 'molv'
				//,range: true
				, trigger: 'click'
			});

			laydate.render({
				elem: '#test6-2' //指定元素
				, type: 'datetime'
				, theme: 'molv'
				//,range: true
				, trigger: 'click'
			});

		});
	</script>
</block>
